/*
 * @Author: your name
 * @Date: 2020-07-03 17:51:24
 * @LastEditTime: 2020-09-17 15:16:11
 * @LastEditors: 天羽落星辰
 * @Description: In User Settings Edit
 * @FilePath: \WWW\frx\public\assets\js\backend\order.js
 */ 
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    // add_url: 'order/add',
                    // edit_url: 'order/edit',
                    del_url: 'order/del',
                    // multi_url: 'order/multi',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'uid', title: __('Uid')},
                        {field: 'uname', title: __('Uname')},
                        {field: 'danhao', title: __('Danhao')},
                        {field: 'zt', title: __('Zt'), formatter: Table.api.formatter.status, searchList: {1: __('进行中'), 0: __('正常完成')}},
                        {field: 'price', title: __('Price'), operate:'BETWEEN', formatter: function (value,row) {return value * 1}},
                        {field: 'shouyi', title: __('Shouyi'), formatter: function (value,row) {return value * 1}},
                        {field: 'zhouqi', title: __('Zhouqi'), operate: false},
                        { field: 'give', title: __('是否赠送'), formatter: Table.api.formatter.status, searchList: {1: __('系统赠送'), 0: __('否')}},
                        {field: 'overtime', title: __('Overtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'stoptime', title: __('Stoptime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'lasttime', title: __('Lasttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'current_profit', title: __('Current_profit'), operate:'BETWEEN', formatter: function (value,row) {return value * 1}},
                        // {field: 'service_charge', title: __('Service_charge'), operate:'BETWEEN', formatter: function (value,row) {return value * 1}},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [
                            {
                                name: 'give',
                                text: __('激活正常合约'),
                                title: __('激活正常合约'),
                                classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                // icon: 'fa fa-magic',
                                url: 'order/give',
                                confirm: '是否激活正常合约?',
                                visible: function (row) {
                                    if(row.give == 1 && row.zt == 1){
                                        return true;
                                    }else{
                                        return false;
                                    }
                                    // console.log(row);
                                    //返回true时按钮显示,返回false隐藏
                                },
                                success: function (data, ret) {
                                    Layer.alert(ret.msg);
                                    $(".btn-refresh").trigger("click");
                                    //如果需要阻止成功提示，则必须使用return false;
                                    //return false;
                                },
                                error: function (data, ret) {
                                    // console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            },
                            {
                                name: 'del',
                                // text: __('激活正常合约'),
                                title: __('删除合约'),
                                classname: 'btn btn-xs btn-danger btn-magic btn-ajax',
                                icon: 'fa fa-trash',
                                url: 'order/del',
                                confirm: '是否删除合约?',
                                success: function (data, ret) {
                                    // console.log(data, ret);

                                    Layer.alert(ret.msg);
                                    $(".btn-refresh").trigger("click");
                                    //如果需要阻止成功提示，则必须使用return false;
                                    //return false;
                                },
                                error: function (data, ret) {
                                    // console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            },
                            // {
                            
                        ],
                        formatter: Table.api.formatter.buttons}

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});